﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Management/manage.master" AutoEventWireup="true" CodeFile="Brand.aspx.cs" Inherits="Management_Common_Brand" Theme="DataWebControls" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link rel="stylesheet" href="<%=ResolveUrl("~/Scripts/swfupload/default.css") %>" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript" src="<%=ResolveUrl("~/Scripts/swfupload/handlers.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveUrl("~/Scripts/swfupload/swfupload.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveUrl("~/Scripts/jquery-ui-dd-sortable.min.js") %>"></script>
    <script language="javascript" type="text/javascript">
        var swfu;

        $(window).load(function () {
            Init_SWFUpload();
        });

        function Init_SWFUpload() {
            swfu = new SWFUpload({
                // Backend Settings
                upload_url: '<%=ResolveUrl("~/Management/upload.aspx") %>',
                post_params: {
                    "ASPSESSID": "<%=Session.SessionID %>"
                },

                // File Upload Settings
                file_size_limit: "2 MB",
                file_types: "*.jpg;*.gif",
                file_types_description: "Images",
                file_upload_limit: "1",    // Zero means unlimited

                // Event Handler Settings - these functions as defined in Handlers.js
                //  The handlers are not part of SWFUpload but are part of my website and control how
                //  my website reacts to the SWFUpload events.
                file_queue_error_handler: fileQueueError,
                file_dialog_complete_handler: fileDialogComplete,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: uploadSuccess,
                upload_complete_handler: uploadComplete,

                // Button settings
                button_image_url: '<%=ResolveUrl("~/Scripts/swfupload/images/XPButtonNoText_160x22.png") %>',
                button_placeholder_id: "spanButtonPlaceholder",
                button_width: 160,
                button_height: 22,
                button_text: '<span class="button">选择图片<span class="buttonSmall">(单文件 2 MB)</span></span>',
                button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 12px; }',
                button_text_top_padding: 1,
                button_text_left_padding: 5,

                // Flash Settings
                flash_url: '<%=ResolveUrl("~/Scripts/swfupload/swfupload.swf") %>', // Relative to this file

                custom_settings: {
                    upload_target: "divFileProgressContainer"
                },

                // Debug Settings
                debug: false
            });
        }


        function formvalidate() {
            var result = true;
            $(".required").each(function () {
                if ($.trim($(this).val()) == "") {
                    $(this).next().text("* required!");
                    result = false;
                }
                else {
                    $(this).next().text("*");
                }
            });
            return result;
        }

        $(function () {
            //拖拽排序
            $("#<%=GridView1.ClientID %> tbody").sortable({
                'update': function (event, ui) {
                    console.log(ui);
                },
                //鼠标接触即开始排序
                'tolerance': 'pointer',
                //定位动画
                'revert': true,
                'opacity': 0.7,
                'cancel': '.HeaderStyle',
                'cursor': 'move'
            });

            $("#sort").click(function () {
                var brands = [];
                $("#<%=GridView1.ClientID %> tbody tr").each(function (k, v) {
                    if (k > 0) {
                        var fields = $(this).find("span"),
                            img = $(this).find("img");
                        brands.push({
                            BrandID: $(fields[0]).text(),
                            BrandName: $(fields[1]).text(),
                            BrandImage: img.attr("src").replace("/SeDuce_WebSite", "~"),
                            Sort: k
                        });
                    }
                });
                $.ajax({
                    type: "POST",
                    url: '<%=ResolveUrl("~/handlers/BrandSortHandler.ashx") %>',
                    dataType: "json",
                    data: { branddata: JSON.stringify({ "BrandList": brands }) },
                    success: function (data) {
                        alert(data.Status == "0" ? "保存成功!" : "保存时发生错误!请重试...");
                        window.location.reload();
                    },
                    error: function (err) {
                        alert("保存时发生错误!请重试...");
                        window.location.reload();
                    }
                });
            });
        });
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" AsyncPostBackTimeout="36000">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <h2 class="clearfix">
                <span class="float_l">品牌管理</span>
            </h2>
            <asp:Panel ID="Panel1" runat="server" CssClass="block">
                <table class="table">
                    <tr>
                        <td class="field">ID:</td>
                        <td><asp:Label ID="lblID" runat="server"></asp:Label></td>
                    </tr>
                    <tr>
                        <td class="field">Name:</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" CssClass="required text"></asp:TextBox><span class="color_red margin5_lr">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="field">Logo:</td>
                        <td>
                            <div id="uploader">
                                <span id="spanButtonPlaceholder"></span>
                            </div>
                            <div id="divFileProgressContainer" style="height: 75px;"></div>
                            <div id="thumbnails" style="display:none;padding:10px; background:#444; border:1px solid #3b3b3b;width:700px;margin-top:20px;">
                                <div id="file_list" style="display:none;margin-bottom:20px;font-weight:bold;">上传图片列表</div>
                            </div>
                        </td>
                    </tr>
                </table>
                <div class="margin10_tb">
                    <asp:LinkButton ID="lbtnSave" runat="server" onclick="lbtnSave_Click" OnClientClick="javascript:return formvalidate();" CssClass="btn">保存</asp:LinkButton>
                    <asp:LinkButton ID="lbtnCancel" runat="server" onclick="lbtnCancel_Click" OnClientClick="javascript:window.location.reload();" CssClass="btn">取消</asp:LinkButton>
                </div>
            </asp:Panel>
            <div class="margin10_tb">
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand">
                    <Columns>
                        <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label ID="lblID" runat="server" Text='<%#Eval("BrandID").ToString() %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name">
                            <ItemTemplate>
                                <asp:Label ID="lblName" runat="server" Text='<%#Eval("BrandName").ToString() %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Logo">
                            <ItemTemplate>
                                <asp:Image ID="imgLogo" runat="server" ImageUrl='<%# ResolveUrl(Eval("BrandImage").ToString()) %>' height="100" />
                                <asp:HiddenField ID="hidLogo" runat="server" Value='<%# Eval("BrandImage").ToString() %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnEdit" CommandName="MOD" runat="server" CssClass="btn">编辑</asp:LinkButton>
                                <asp:LinkButton ID="lbtnDelete" CommandName="DEL" runat="server" CssClass="btn" OnClientClick="javascript:return confirm('确认删除么？');">删除</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <div class="pager margin10_tb">
                <asp:Repeater ID="rptPageFliper" runat="server">
                    <ItemTemplate>
                        <span class='<%#(((PageNumberItem)Container.DataItem).IsCurrentPage) ? "current": string.Empty%>' class="paging">
                            <asp:LinkButton ID="lbtnPager" runat="server" CommandName="<%# ((PageNumberItem)Container.DataItem).PageNumberCommand%>"
                                Text="<%# ((PageNumberItem)Container.DataItem).PageNumberText%>" Enabled='<%# !(((PageNumberItem)Container.DataItem).IsCurrentPage) %>'
                                Style='<%#(((PageNumberItem)Container.DataItem).IsCurrentPage) ? "color:#eee;": "color:#eee;"%>'
                                Font-Underline="false"></asp:LinkButton>
                        </span>
                    </ItemTemplate>
                </asp:Repeater>
                </div>
                <div class="margin10_tb">
                    <a id="sort" class="btn">保存当前排序</a>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

